/*
 * AgendaNotePanel.java
 *
 * Created on 15 mars 2008, 15:15
 */

package sheep.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.jdesktop.animation.timing.Animator;
import org.jdesktop.animation.timing.TimingTarget;
import org.jdesktop.swingx.JXLabel;
import org.jdesktop.swingx.JXPanel;

import sheep.controller.Workspace;
import sheep.model.Worker;
import sheep.view.Component.UserTableModel;
import sheep.view.Component.ActionButton;
import sheep.view.Component.RoundedPanel;
import sheep.view.graphics2d.AnimationUtil;
import java.io.File;
import java.net.URL;
import javax.swing.filechooser.*;
import org.jdesktop.swingx.JXImagePanel;

import org.jdesktop.swingx.VerticalLayout;
import sheep.view.Component.ImageChooser.ImageFilter;
import sheep.view.Component.ImageChooser.ImagePreview;
import sheep.view.Component.OneSideRoundedPanel;
import sheep.view.Component.OneSideRoundedPanel.OneSideRoundedPanelMode;

/**
 *
 * @author  geek
 */
public class UserEditPanel extends JXPanel {
  
  private JXPanel MainPanel;
  private javax.swing.JPanel centerPanel;
  private javax.swing.JButton cornerQuitBttn;
  private javax.swing.JPanel northPanel;
  private javax.swing.JButton quitBttn;
  private javax.swing.JPanel southPanel;
  private javax.swing.JButton validBttn;
  
  
  private javax.swing.JLabel beginLabel;
  private javax.swing.JPanel beginPanel;
  private javax.swing.JButton btnPhoto;
  private javax.swing.JLabel calendrierLabel;
  private javax.swing.JLabel calendrierLabel1;
  private javax.swing.JPanel calendrierPanel;
  private javax.swing.JPanel calendrierPanel1;
  private javax.swing.JPanel calendrierPanel2;
  private javax.swing.JPanel endDatePanel;
  private javax.swing.JPanel endDatePanel1;
  private javax.swing.JPanel endDatePanel2;
  private javax.swing.JPanel endDatePanel3;
  private javax.swing.JPanel endDatePanel4;
  private javax.swing.JLabel endLabel;
  private javax.swing.JLabel endLabel1;
  private javax.swing.JLabel endLabel2;
  private javax.swing.JPanel endPanel;
  private javax.swing.JPanel endPanel1;
  private javax.swing.JPanel endPanel2;
  private javax.swing.JPanel jPanel1;
  private javax.swing.JPanel jPanel10;
  private javax.swing.JPanel jPanel11;
  private javax.swing.JPanel jPanel12;
  private javax.swing.JPanel jPanel2;
  private javax.swing.JPanel jPanel3;
  private javax.swing.JPanel jPanel4;
  private javax.swing.JPanel jPanel5;
  private javax.swing.JPanel jPanel6;
  private javax.swing.JPanel jPanel7;
  private javax.swing.JPanel jPanel8;
  private javax.swing.JPanel jPanel9;
  private javax.swing.JPanel leftPanel;
  private javax.swing.JPanel rightPanel;
  private javax.swing.JLabel titleLabel2;
  private javax.swing.JLabel titleLabel3;
  private javax.swing.JPanel titlePanel3;
  private javax.swing.JTextField txtAdresse;
  private org.jdesktop.swingx.JXDatePicker txtDateNaissance;
  private javax.swing.JTextField txtJob;
  private javax.swing.JTextField txtNom;
  private javax.swing.JTextField txtNpa;
  private javax.swing.JTextField txtPhoto;
  private javax.swing.JTextField txtPrenom;
  private javax.swing.JTextField txtVille;
  // End of variables declaration
  
  private Workspace workSpace;
  private Worker worker;
  private JTable table;
  private UserTableModel model;
  private UserPanel userPanel;
  
  private static int photoHeight=100, photoWidth=100;

  
  public void setWorker(Worker w) { this.worker = w; }
  
  public void setFieldsValues() {
    txtPrenom.setText("");
    txtNom.setText("");
    txtPhoto.setText("");
    txtDateNaissance.setDate(new Date(System.currentTimeMillis()));
    txtAdresse.setText("");
    txtNpa.setText("");
    txtVille.setText("");
    txtJob.setText("");

    if(this.worker != null) {
      txtPrenom.setText(worker.getFirstName());
      txtNom.setText(worker.getLastName());
      txtPhoto.setText(worker.getPicturesURL().toString());
      txtDateNaissance.setDate(worker.getBirthDate().getTime());
      txtAdresse.setText(worker.getAdresse());
      txtNpa.setText(worker.getPostCode());
      txtVille.setText(worker.getTown());
      txtJob.setText(worker.getJob());
    }
  }
  
  public UserEditPanel(Workspace workSpace, Worker w, JTable table, UserTableModel model, UserPanel userPanel) {
    this.workSpace = workSpace;
    this.worker = w;
    this.table = table;
    this.model = model;
    this.userPanel = userPanel;
    initComponents();
  }
  
  private void initComponents() {
    

    rightPanel = new javax.swing.JPanel();
    titlePanel3 = new javax.swing.JPanel();
    titleLabel3 = new javax.swing.JLabel();
    txtPrenom = new javax.swing.JTextField();
    jPanel8 = new javax.swing.JPanel();
    jPanel3 = new javax.swing.JPanel();
    jPanel6 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    beginPanel = new javax.swing.JPanel();
    beginLabel = new javax.swing.JLabel();
    txtDateNaissance = new org.jdesktop.swingx.JXDatePicker();
    jPanel4 = new javax.swing.JPanel();
    endPanel = new javax.swing.JPanel();
    endDatePanel = new javax.swing.JPanel();
    txtJob = new javax.swing.JTextField();
    endLabel = new javax.swing.JLabel();
    calendrierPanel2 = new javax.swing.JPanel();
    calendrierPanel = new javax.swing.JPanel();
    calendrierLabel = new javax.swing.JLabel();
    endDatePanel1 = new javax.swing.JPanel();
    txtPhoto = new javax.swing.JTextField();
    btnPhoto = new ActionButton();
    jPanel9 = new javax.swing.JPanel();
    leftPanel = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    txtNom = new javax.swing.JTextField();
    titleLabel2 = new javax.swing.JLabel();
    jPanel5 = new javax.swing.JPanel();
    jPanel11 = new javax.swing.JPanel();
    jPanel10 = new javax.swing.JPanel();
    endPanel2 = new javax.swing.JPanel();
    endDatePanel4 = new javax.swing.JPanel();
    txtVille = new javax.swing.JTextField();
    endLabel2 = new javax.swing.JLabel();
    jPanel7 = new javax.swing.JPanel();
    endPanel1 = new javax.swing.JPanel();
    endDatePanel3 = new javax.swing.JPanel();
    txtNpa = new javax.swing.JTextField();
    endLabel1 = new javax.swing.JLabel();
    calendrierPanel1 = new javax.swing.JPanel();
    calendrierLabel1 = new javax.swing.JLabel();
    endDatePanel2 = new javax.swing.JPanel();
    txtAdresse = new javax.swing.JTextField();
    jPanel12 = new javax.swing.JPanel();
    
    MainPanel = new JXPanel();
    centerPanel = new javax.swing.JPanel();  
   
    northPanel = new javax.swing.JPanel();
    
    javax.swing.JLabel mainTitleLabel = new javax.swing.JLabel();
    
    cornerQuitBttn = new javax.swing.JButton();
    southPanel = new javax.swing.JPanel();
    validBttn = new ActionButton();
    quitBttn = new ActionButton();
    
    
    
    txtPrenom.setText("                          ");

    setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    setOpaque(false);
    setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.PAGE_AXIS));

    MainPanel.setBackground(new java.awt.Color(255, 255, 255));
    MainPanel.setMaximumSize(new java.awt.Dimension(2147483647, 300));
    MainPanel.setMinimumSize(new java.awt.Dimension(73, 200));
    MainPanel.setPreferredSize(new java.awt.Dimension(100, 200));
    MainPanel.setLayout(new java.awt.BorderLayout());

    centerPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 0, 1, 0));
    centerPanel.setOpaque(false);
    centerPanel.setLayout(new BorderLayout());
    

    
    
    
    
    JPanel temp = new JPanel();
    
    temp.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 0, 1, 0));
    temp.setOpaque(false);
    temp.setLayout(new java.awt.GridLayout());

    rightPanel.setOpaque(false);
    rightPanel.setPreferredSize(new java.awt.Dimension(350, 300));
    rightPanel.setLayout(new javax.swing.BoxLayout(rightPanel, javax.swing.BoxLayout.PAGE_AXIS));

    titlePanel3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 0, 5));
    titlePanel3.setOpaque(false);
    titlePanel3.setPreferredSize(new java.awt.Dimension(160, 100));
    titlePanel3.setLayout(new java.awt.BorderLayout());

    titleLabel3.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleLabel3.setText("Prénom");
    titleLabel3.setForeground(new java.awt.Color(255, 255, 255));
    titlePanel3.add(titleLabel3, java.awt.BorderLayout.WEST);

    txtPrenom.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtPrenom.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtPrenom.setText("jTextField1");
    txtPrenom.setOpaque(false);
    txtPrenom.setPreferredSize(new java.awt.Dimension(200, 15));
    txtPrenom.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      }
    });
    titlePanel3.add(new RoundedPanel (txtPrenom), java.awt.BorderLayout.EAST);

    jPanel8.setOpaque(false);
    titlePanel3.add(jPanel8, java.awt.BorderLayout.CENTER);

    rightPanel.add(new OneSideRoundedPanel(titlePanel3,OneSideRoundedPanelMode.WEST ));

    jPanel3.setOpaque(false);
    rightPanel.add(jPanel3);

    jPanel6.setOpaque(false);
    jPanel6.setLayout(new java.awt.BorderLayout());

    jPanel2.setOpaque(false);
    jPanel2.setLayout(new javax.swing.BoxLayout(jPanel2, javax.swing.BoxLayout.PAGE_AXIS));

    beginPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    beginPanel.setOpaque(false);
    beginPanel.setPreferredSize(new java.awt.Dimension(160, 100));
    beginPanel.setLayout(new java.awt.BorderLayout());

    beginLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    beginLabel.setText("Date de naissance");
    beginLabel.setForeground(new java.awt.Color(255, 255, 255));
    beginPanel.add(beginLabel, java.awt.BorderLayout.WEST);

    txtDateNaissance.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtDateNaissance.setPreferredSize(new java.awt.Dimension(200, 15));
    beginPanel.add(new RoundedPanel (txtDateNaissance), java.awt.BorderLayout.EAST);

    jPanel2.add(beginPanel);

    jPanel4.setOpaque(false);
    //jPanel2.add(jPanel4);

    endPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    endPanel.setOpaque(false);
    endPanel.setPreferredSize(new java.awt.Dimension(160, 100));
    endPanel.setLayout(new java.awt.BorderLayout());

    endDatePanel.setOpaque(false);
    endDatePanel.setPreferredSize(new java.awt.Dimension(306, 10));
    endDatePanel.setLayout(new java.awt.BorderLayout());

    txtJob.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtJob.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtJob.setText("jTextField1");
    txtJob.setOpaque(false);
    txtJob.setPreferredSize(new java.awt.Dimension(200, 15));
    endDatePanel.add(new RoundedPanel (txtJob), java.awt.BorderLayout.EAST);

    endPanel.add(endDatePanel, java.awt.BorderLayout.EAST);

    endLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endLabel.setText("job");
    endLabel.setForeground(new java.awt.Color(255, 255, 255));
    endPanel.add(endLabel, java.awt.BorderLayout.WEST);

    jPanel2.add(endPanel);

    calendrierPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    calendrierPanel2.setOpaque(false);
    calendrierPanel2.setPreferredSize(new java.awt.Dimension(160, 100));
    calendrierPanel2.setLayout(new java.awt.BorderLayout());

    calendrierPanel.setOpaque(false);
    calendrierPanel.setPreferredSize(new java.awt.Dimension(160, 10));
    calendrierPanel.setLayout(new java.awt.BorderLayout());

    calendrierLabel.setFont(new java.awt.Font("Times New Roman", 1, 14));
    calendrierLabel.setText("photo");
    calendrierLabel.setForeground(new java.awt.Color(255, 255, 255));
    calendrierPanel.add(calendrierLabel, java.awt.BorderLayout.WEST);

    endDatePanel1.setOpaque(false);
    endDatePanel1.setPreferredSize(new java.awt.Dimension(200, 25));
    endDatePanel1.setLayout(new java.awt.BorderLayout(20, 0));

    txtPhoto.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtPhoto.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtPhoto.setText("jTextField1");
    txtPhoto.setOpaque(false);
    txtPhoto.setPreferredSize(new java.awt.Dimension(105, 15));
    txtPhoto.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      }
    });
    endDatePanel1.add(new RoundedPanel (txtPhoto), java.awt.BorderLayout.WEST);

    btnPhoto.setText("Choisir");
    
    endDatePanel1.add(btnPhoto, java.awt.BorderLayout.EAST);

    calendrierPanel.add(endDatePanel1, java.awt.BorderLayout.EAST);

    calendrierPanel2.add(calendrierPanel, java.awt.BorderLayout.CENTER);

    jPanel2.add(calendrierPanel2);

    jPanel6.add( new RoundedPanel (jPanel2), java.awt.BorderLayout.CENTER);

    jPanel9.setOpaque(false);
    jPanel9.setPreferredSize(new java.awt.Dimension(5, 10));
    jPanel6.add(jPanel9, java.awt.BorderLayout.EAST);

    rightPanel.add(jPanel6);

    temp.add(rightPanel);

    leftPanel.setOpaque(false);
    leftPanel.setPreferredSize(new java.awt.Dimension(350, 300));
    leftPanel.setLayout(new javax.swing.BoxLayout(leftPanel, javax.swing.BoxLayout.PAGE_AXIS));

    jPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 5, 10, 1));
    jPanel1.setOpaque(false);
    jPanel1.setPreferredSize(new java.awt.Dimension(160, 99));
    jPanel1.setLayout(new java.awt.BorderLayout());

    txtNom.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtNom.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtNom.setText("jTextField1");
    txtNom.setOpaque(false);
    txtNom.setPreferredSize(new java.awt.Dimension(200, 15));
    txtNom.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {

      }
    });
    jPanel1.add(new RoundedPanel (txtNom), java.awt.BorderLayout.EAST);

    titleLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14));
    titleLabel2.setText("Nom");
    titleLabel2.setForeground(new java.awt.Color(255, 255, 255));
    jPanel1.add(titleLabel2, java.awt.BorderLayout.WEST);

    leftPanel.add( new OneSideRoundedPanel(jPanel1,OneSideRoundedPanelMode.EAST));

    jPanel5.setOpaque(false);
    leftPanel.add(jPanel5);

    jPanel11.setOpaque(false);
    jPanel11.setLayout(new java.awt.BorderLayout());

    jPanel10.setOpaque(false);
    jPanel10.setLayout(new javax.swing.BoxLayout(jPanel10, javax.swing.BoxLayout.PAGE_AXIS));

    endPanel2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    endPanel2.setOpaque(false);
    endPanel2.setPreferredSize(new java.awt.Dimension(160, 100));
    endPanel2.setLayout(new java.awt.BorderLayout());

    endDatePanel4.setOpaque(false);
    endDatePanel4.setPreferredSize(new java.awt.Dimension(306, 10));
    endDatePanel4.setLayout(new java.awt.BorderLayout());

    txtVille.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtVille.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtVille.setText("jTextField1");
    txtVille.setOpaque(false);
    txtVille.setPreferredSize(new java.awt.Dimension(200, 15));
    endDatePanel4.add(new RoundedPanel (txtVille), java.awt.BorderLayout.EAST);

    endPanel2.add(endDatePanel4, java.awt.BorderLayout.EAST);

    endLabel2.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endLabel2.setText("Ville");
    endLabel2.setForeground(new java.awt.Color(255, 255, 255));
    endPanel2.add(endLabel2, java.awt.BorderLayout.WEST);

    jPanel10.add(endPanel2);

    jPanel7.setOpaque(false);
    //jPanel10.add(jPanel7);

    endPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    endPanel1.setOpaque(false);
    endPanel1.setPreferredSize(new java.awt.Dimension(160, 100));
    endPanel1.setLayout(new java.awt.BorderLayout());

    endDatePanel3.setOpaque(false);
    endDatePanel3.setPreferredSize(new java.awt.Dimension(306, 20));
    endDatePanel3.setLayout(new java.awt.BorderLayout());

    txtNpa.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtNpa.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtNpa.setText("jTextField1");
    txtNpa.setOpaque(false);
    txtNpa.setPreferredSize(new java.awt.Dimension(200, 15));
    endDatePanel3.add(new RoundedPanel (txtNpa), java.awt.BorderLayout.EAST);

    endPanel1.add(endDatePanel3, java.awt.BorderLayout.EAST);

    endLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14));
    endLabel1.setText("NPA");
    endLabel1.setForeground(new java.awt.Color(255, 255, 255));
    endPanel1.add(endLabel1, java.awt.BorderLayout.WEST);

    jPanel10.add(endPanel1);

    calendrierPanel1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 10, 1));
    calendrierPanel1.setOpaque(false);
    calendrierPanel1.setPreferredSize(new java.awt.Dimension(160, 100));
    calendrierPanel1.setLayout(new java.awt.BorderLayout());

    calendrierLabel1.setFont(new java.awt.Font("Times New Roman", 1, 14));
    calendrierLabel1.setText("Adresse");
    calendrierLabel1.setForeground(new java.awt.Color(255, 255, 255));
    calendrierPanel1.add(calendrierLabel1, java.awt.BorderLayout.WEST);

    endDatePanel2.setOpaque(false);
    endDatePanel2.setPreferredSize(new java.awt.Dimension(200, 25));
    endDatePanel2.setLayout(new java.awt.BorderLayout(20, 0));

    txtAdresse.setFont(new java.awt.Font("Times New Roman", 1, 14));
    txtAdresse.setHorizontalAlignment(javax.swing.JTextField.LEFT);
    txtAdresse.setText("jTextField1");
    txtAdresse.setOpaque(false);
    //txtAdresse.s
    txtAdresse.setPreferredSize(new java.awt.Dimension(200, 20));
    endDatePanel2.add(new RoundedPanel (txtAdresse), java.awt.BorderLayout.EAST);

    calendrierPanel1.add(endDatePanel2, java.awt.BorderLayout.EAST);

    jPanel10.add(calendrierPanel1);

    jPanel11.add(new RoundedPanel(jPanel10), java.awt.BorderLayout.CENTER);

    jPanel12.setMinimumSize(new java.awt.Dimension(5, 10));
    jPanel12.setOpaque(false);
    jPanel12.setPreferredSize(new java.awt.Dimension(5, 10));
    jPanel11.add(jPanel12, java.awt.BorderLayout.WEST);

    leftPanel.add(jPanel11);

    temp.add(leftPanel);
    
    
    centerPanel. add(temp);
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    btnPhoto.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        JFileChooser chooser = new JFileChooser();
        FileFilter filter = new ImageFilter();
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setFileFilter(filter);
      //  chooser.setFileView(new ImageFileView());
        chooser.setAccessory(new ImagePreview(chooser));
        
        int returnVal = chooser.showOpenDialog(new JPanel());
        if(returnVal == JFileChooser.APPROVE_OPTION) {
          String fileChoosed;
          fileChoosed = chooser.getCurrentDirectory() + 
                System.getProperties().getProperty("file.separator") + 
                chooser.getSelectedFile().getName();
           
          txtPhoto.setText(fileChoosed);
        }
      }
    });

    
    
    ///////////////////////////////
    //DESSIN PRINCIPALE
    /////////////////////////////////////////////////////////////
    
    MainPanel.add(centerPanel, java.awt.BorderLayout.CENTER);

    northPanel.setOpaque(false);
    northPanel.setLayout(new java.awt.BorderLayout());
    northPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 5, 10));
    mainTitleLabel.setFont(new java.awt.Font("Tahoma", 1, 20));
    mainTitleLabel.setForeground(new java.awt.Color(255, 255, 255));
    mainTitleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    mainTitleLabel.setText("Informations sur les participants");
    northPanel.add(mainTitleLabel, java.awt.BorderLayout.CENTER);

    cornerQuitBttn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close.png"))); // NOI18N
    cornerQuitBttn.setToolTipText("Close editor");
    cornerQuitBttn.setBorder(null);
    cornerQuitBttn.setBorderPainted(false);
    cornerQuitBttn.setContentAreaFilled(false);
    cornerQuitBttn.setFocusPainted(false);
    cornerQuitBttn.setFocusable(false);
    cornerQuitBttn.setMargin(new java.awt.Insets(0, 0, 0, 0));
    cornerQuitBttn.setPressedIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-pressed.png"))); // NOI18N
    cornerQuitBttn.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/images/button-close-over.png"))); // NOI18N
    cornerQuitBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        cornerQuitBttnActionPerformed(evt);
      }
    });
    northPanel.add(cornerQuitBttn, java.awt.BorderLayout.EAST);

    MainPanel.add(northPanel, java.awt.BorderLayout.PAGE_START);

    //southPanel.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 1, 0, 1));
    southPanel.setOpaque(false);
    southPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 15, 2));

    validBttn.setText("   Ok    ");
    southPanel.add(validBttn);
    validBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        if (txtNom.getText().length() >0)
          OKBttnActionPerformed(evt);
      }
    });
    
    quitBttn.setText("Annuler");
    quitBttn.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        quitBttnActionPerformed(evt);
      }
    });
    southPanel.add(quitBttn);

    MainPanel.add(southPanel, java.awt.BorderLayout.PAGE_END);
    MainPanel.setOpaque(true);
    MainPanel.setBackgroundPainter(new sheep.view.utils.swingx.PainterBlackCustom());
    add(new RoundedPanel(MainPanel));
  }// </editor-fold>

  private void cornerQuitBttnActionPerformed(java.awt.event.ActionEvent evt) {
    final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {}
      @Override
      public void end() {
        setVisible2(false);
        parent.repaint();
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
}

  private void quitBttnActionPerformed(java.awt.event.ActionEvent evt) {
        final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {}
      @Override
      public void end() {
        setVisible2(false);
        parent.repaint();
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
  }
 
    private void OKBttnActionPerformed(java.awt.event.ActionEvent evt) {
        final Container parent = this.getParent();
    Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
    fadeOut.addTarget(new TimingTarget() {
      @Override
      public void begin() {
        Calendar c = Calendar.getInstance();
        c.setTime(txtDateNaissance.getDate());
        if(worker!=null) {
          worker.setFirstName(txtPrenom.getText());
          worker.setLastName(txtNom.getText());
          worker.setBirthDate(c);
          worker.setAdresse(txtAdresse.getText());
          worker.setPostCode(txtNpa.getText());
          worker.setTown(txtVille.getText());
          worker.setPictures(txtPhoto.getText());
          worker.setJob(txtJob.getText());
          workSpace.setCurrentWorker(worker);
        }
        else {
          Worker w = new Worker(txtPrenom.getText(), txtNom.getText(), c,
                  txtAdresse.getText(), txtNpa.getText(), txtVille.getText(),
                  txtPhoto.getText(), txtJob.getText());
          workSpace.getWorkersList().add(w);
          workSpace.setCurrentWorker(w);
        }
        model.setData(workSpace.getWorkersList());
        table.setModel(model);
        table.repaint();
        userPanel.refresh();     
      }
      @Override
      public void end() {

        setVisible2(false);        
        parent.repaint();
        userPanel.refresh();  
       
      }
      @Override
      public void timingEvent(float f) {}
      @Override
      public void repeat() {}
    });
    fadeOut.start();
  }
    
    void setVisible2 (boolean aFlag){
    super.setVisible(aFlag);
    setEnabled(aFlag);
    setFocusable(aFlag);
    if (aFlag){
      ///////////////////////////
      //INIT
      ///////////////////////////
    }
  }


  @Override
  public void setVisible(final boolean aFlag) {
    final Container parent = this.getParent();   
    if (!aFlag){ 
      Animator fadeOut = AnimationUtil.createFadeOutAnimation(this);
      fadeOut.addTarget(new TimingTarget() {
        @Override
        public void begin() {}
        @Override
        public void end() {
            setVisible2(false);
            parent.repaint();            
        }
        @Override
        public void timingEvent(float f) {}
        @Override
        public void repeat() {}
      });
      fadeOut.start();
    }else{
        Animator fadeIn = AnimationUtil.createFadeInAnimation(this);
        fadeIn.addTarget(new TimingTarget() {
        @Override
        public void begin() {setVisible2(true);}
        @Override
        public void end() {
          parent.repaint();
        }
        @Override
        public void timingEvent(float f) {}
        @Override
        public void repeat() {}
      });
      fadeIn.start();   
    }
  }
}



